package com.approval.approvalapp.knowledge.zcfg.adapter;

import android.content.Context;
import android.content.Intent;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.approval.approvalapp.R;
import com.approval.approvalapp.WebActivity;
import com.approval.approvalapp.bean.ZcFgBean;
import com.approval.approvalapp.util.DateUtils;

import java.util.Date;
import java.util.List;

/**
 * Created by louyulin on 2019/4/28.
 */

public class ZcfgrvAdapter extends RecyclerView.Adapter<ZcfgrvAdapter.Holder> {

    List<ZcFgBean> zcFgBeanList;
    Context context;


    public void setZcFgBeanList(List<ZcFgBean> zcFgBeanList) {
        this.zcFgBeanList = zcFgBeanList;
        notifyDataSetChanged();
    }

    @Override
    public Holder onCreateViewHolder(ViewGroup parent, int viewType) {
        context = parent.getContext();
        View view = LayoutInflater.from(context).inflate(R.layout.zcfg_item,parent,false);
        Holder holder = new Holder(view);
        return holder;
    }

    @Override
    public void onBindViewHolder(Holder holder, final int position) {
        holder.tv1.setText(zcFgBeanList.get(position).getTitle());
        int add_time = zcFgBeanList.get(position).getAdd_time();
        String s = DateUtils.parseDateToStr(new Date(Long.valueOf(add_time) * 1000), DateUtils.DATE_APP);
        holder.tv2.setText(s);
        holder.tv3.setText(zcFgBeanList.get(position).getType());

        holder.root.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent();
                intent.putExtra("url", "http://58.16.86.141:8321/CIO.api/api/v1/center/data_index?id=" + zcFgBeanList.get(position)
                .getId());
                intent.setClass(context, WebActivity.class);
                context.startActivity(intent);
            }
        });
    }

    @Override
    public int getItemCount() {
        if (zcFgBeanList == null){
            return 0;
        }else {
            return zcFgBeanList.size();
        }
    }

    class Holder extends RecyclerView.ViewHolder{
        TextView tv1 , tv2,tv3;
        LinearLayout root;
        public Holder(View itemView) {
            super(itemView);
            tv1 = itemView.findViewById(R.id.tv1);
            tv2 = itemView.findViewById(R.id.tv2);
            tv3 = itemView.findViewById(R.id.tv3);
            root = itemView.findViewById(R.id.root);
        }
    }
}
